﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WordWars
{
    public partial class Word : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            h1Word.InnerText = Request.QueryString["word"];

            // string variable to store the connection string
            // defined in connectionstrings section of web.config file.
            //string connStr = ConfigurationManager.ConnectionStrings["MySqlCon"].ConnectionString;

            // object created for SqlConnection Class.
            MySqlConnection mySQLconnection = new MySqlConnection();
            mySQLconnection.ConnectionString = "Server=mysql.serversfree.com;Database=u994204987_wordwars;User=mysql.serversfree.com;Password=weekend1;";

            // if condition that can be used to check the sql connection
            // whether it is already open or not.
            if (mySQLconnection.State == ConnectionState.Closed)
            {
                mySQLconnection.Open();
            }

            // SQL Select Command
            MySqlCommand mySqlSelect = new MySqlCommand("SELECT * FROM Images WHERE Word = " + Request.QueryString["word"] + ")", mySQLconnection);

            mySqlSelect.CommandType = CommandType.Text;

            rptImages.DataSource = mySqlSelect;
            rptImages.DataBind();

            // if condition that can be used to check the sql connection
            // if it is open then close it.
            if (mySQLconnection.State == ConnectionState.Open)
            {
                mySQLconnection.Close();
            }

        }
    }
}